/**
  *  @Description  : oled low level for u8g2 library
  *  @Version      : 1.0
  *  @Author       : simon.yuan
  *  @Date         : 2022-02-14 16:11:10
  *  @LastEditors  : simon.yuan
  *  @LastEditTime : 2022-02-14 22:31:42
  *  @FilePath     : \\oled12864_ssd1306\\user\\bsp\\oled\\oledu8g2.h
  *  @Copyright (C) 2022 QinJin Electronics. All rights reserved.
  */
#ifndef __OLEDU8G2_H__
#define __OLEDU8G2_H__

#include "u8g2.h"
#include "u8x8.h"
#include "stm32f10x.h"

#define SW_IIC                  0
#define HW_IIC                  1

#define OLED_CMD                0
#define OLED_DATA               1

// IIC_SCL
#define SCL_GPIOClock           RCC_APB2Periph_GPIOB
#define SCL_GPIO                GPIOB
#define SCL_GPIO_Pin            GPIO_Pin_6
//IIC_SDA
#define SDA_GPIOClock           RCC_APB2Periph_GPIOB
#define SDA_GPIO                GPIOB
#define SDA_GPIO_Pin            GPIO_Pin_7

// IIC default address
#define OLED_ADDRESS            0x78

#if SW_IIC
void OLED_InitGPIO(void);
uint8_t stm32_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);

#elif HW_IIC
/* Timeout time setup */
#define I2CT_FLAG_TIMEOUT       ((uint32_t)0x1000)
#define I2CT_LONG_TIMEOUT       ((uint32_t)(10 * I2CT_FLAG_TIMEOUT))

void OLED_Init(void);
void I2C_WriteByte(uint8_t addr, uint8_t data);
uint8_t I2C_WriteBytes(uint8_t WriteAddr, uint8_t *pBuffer, uint8_t NumByteToWrite);
uint8_t I2C_ReadBytes(uint8_t ReadAddr, uint8_t *pBuffer, uint16_t NumByteToRead);
uint8_t u8x8_byte_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
uint8_t stm32_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
#endif

void u8g2Init(u8g2_t *u8g2);

#endif
